package demo;

import java.util.Arrays;
import java.util.List;

/**
 * 快速排序
 */
public class QuickSort {

    public static void main(String[] args) {
        List<String> EXCEPTIONS = Arrays.asList("$db", "$ref", "$id","$");

        System.out.println(EXCEPTIONS.contains("$db"));

//        int[] arrs = {1, 3, 4, 1, 3, 2, 123, 12, 56, 3, 0, 9};
//        quickSort(arrs, 0, arrs.length-1);
//
//        for (int i : arrs) {
//            System.out.print(i + ",");
//        }
    }


    public static int[] quickSort(int[] arrs, int left, int right) {

        if (left < right) {
            //首先获取到left的位置
            int partitionIndex = partition(arrs, left, right);
            //递归
            quickSort(arrs, left, partitionIndex - 1);
            quickSort(arrs, partitionIndex + 1, right);
        }
        return arrs;
    }


    //分区
    public static int partition(int[] arr, int left, int right) {

        //获取一个基准
        int pivot = left;

        int index = pivot + 1;

        for (int i = index; i <= right; i++) {
            if (arr[i] < arr[pivot]) {
                swap(arr, i, index);
                index++;
            }
        }
        swap(arr, pivot, index - 1);
        return index - 1;
    }

    private static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
